raises: add missing | metacharacter to is_fully_escaped and unescape#14222
Open
bysiber wants to merge 3 commits intopytest-dev:mainfrom
Open
raises: add missing | metacharacter to is_fully_escaped and unescape#14222bysiber wants to merge 3 commits intopytest-dev:mainfrom
bysiber wants to merge 3 commits intopytest-dev:mainfrom
Conversation
The pipe character is a regex metacharacter (alternation operator) but is_fully_escaped did not include it, so a match pattern like '^foo|bar$' would be wrongly identified as a fully-escaped literal. This causes rawmatch to be set incorrectly, leading to misleading diff output on match failure. Also add | to the unescape function's character class for consistency.
Member
|
Similarly to your other PRs I commented on, could you please add a regression test to catch this issue? |
Test that | is recognized as a regex metacharacter, not treated as a literal. Also verify that unescape handles escaped pipes correctly.
for more information, see https://pre-commit.ci
Author
|
Added a regression test that verifies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
is_fully_escapedchecks whether a match pattern body (inside^...$) contains only escaped regex metacharacters, so pytest knows it can treat it as a literal string for diff output. The current metacharacter list is:This is missing
|, the regex alternation operator. A pattern like^foo|bar$would pass theis_fully_escapedcheck even though the|makes it a regex alternation rather than a literal. This causesrawmatchto be set to the unescaped valuefoo|bar, leading to a misleading diff in the failure message.The
unescapefunction has the same omission in its character class, so\|wouldn't be unescaped even if someone properly escaped it.This adds
|to both the metacharacter list inis_fully_escapedand the character class inunescape.